package com.traveling.hztraveling.controller;


import com.traveling.hztraveling.context.BaseContext;
import com.traveling.hztraveling.entity.po.HzUser;
import com.traveling.hztraveling.entity.vo.Result;
import com.traveling.hztraveling.service.IHzUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LHD
 * @since 2025-05-29
 */
@RestController
@RequestMapping("/login")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "用户登录相关接口")
public class HzUserController {

    private final IHzUserService hzUserService;

    @PostMapping()
    @ApiOperation("校验登录功能")
    public Result<HzUser> login(@RequestBody HzUser hzUser) {
        Integer flat = hzUserService.login(hzUser);
        if (flat!=0){
            log.info("登录成功");
            hzUser.setId(flat);
            log.info("用户:{}", Result.success(hzUser));
            return Result.success(hzUser);
        }
        else if (flat==100){
            hzUser.setId(100);
            return Result.success(hzUser);
        }
        else {
            log.info("登录失败");
            throw new RuntimeException("用户名或密码错误");
        }

    }

    @GetMapping("/getAllUsers")
    @ApiOperation("获取所有用户信息")
    public Result<List<HzUser>> getAllUsers() {
        log.info("获取所有用户信息:{}", hzUserService.list());
        return Result.success(hzUserService.list());
    }

}
